//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "NullCommodityType.h"
using namespace Cephei::QL::Experimental::Commodities;
#include <gen/QL/Experimental/Commodities/CommodityType.h>
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Experimental::Commodities::CNullCommodityType::CNullCommodityType () : CCommodityType(CNullCommodityType::typeid)
{
    try
    {
#ifdef HANDLE
        _phNullCommodityType = NULL;
#endif
        _ppNullCommodityType = new boost::shared_ptr<QuantLib::NullCommodityType> (new QuantLib::NullCommodityType ( ));
        SetCommodityType (boost::dynamic_pointer_cast<QuantLib::CommodityType> (*_ppNullCommodityType));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Experimental::Commodities::CNullCommodityType::CNullCommodityType (boost::shared_ptr<QuantLib::NullCommodityType>& childNative, Object^ owner) : CCommodityType(CNullCommodityType::typeid)
{
#ifdef HANDLE
	_phNullCommodityType = NULL;
#endif
	_ppNullCommodityType = &childNative;
    _ppCommodityType = new boost::shared_ptr<QuantLib::CommodityType> (boost::dynamic_pointer_cast<QuantLib::CommodityType> (*_ppNullCommodityType));
}
Cephei::QL::Experimental::Commodities::CNullCommodityType::CNullCommodityType (QuantLib::NullCommodityType& childNative, Object^ owner) : CCommodityType(CNullCommodityType::typeid)
{
#ifdef HANDLE
	_phNullCommodityType = NULL;
#endif
	_ppNullCommodityType = new boost::shared_ptr<QuantLib::NullCommodityType> (&childNative);
    _ppCommodityType = new boost::shared_ptr<QuantLib::CommodityType> (boost::dynamic_pointer_cast<QuantLib::CommodityType> (*_ppNullCommodityType));
    _NullCommodityTypeOwner = owner;
    _CommodityTypeOwner = owner;
}

Cephei::QL::Experimental::Commodities::CNullCommodityType::CNullCommodityType (CNullCommodityType^ copy) : CCommodityType(CNullCommodityType::typeid)
{
#ifdef HANDLE
	_phNullCommodityType = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppNullCommodityType = new boost::shared_ptr<QuantLib::NullCommodityType> (copy->GetShared());
        _ppCommodityType = new boost::shared_ptr<QuantLib::CommodityType> (boost::dynamic_pointer_cast<QuantLib::CommodityType> (*_ppNullCommodityType));
    }
}
Cephei::QL::Experimental::Commodities::CNullCommodityType::CNullCommodityType (System::Type^ t) : CCommodityType(CNullCommodityType::typeid)
{
#ifdef HANDLE
	_phNullCommodityType = NULL;
#endif
	if (!t->IsSubclassOf(CNullCommodityType::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Experimental::Commodities::CNullCommodityType::CNullCommodityType (QuantLib::Handle<QuantLib::NullCommodityType>& childNative, Object^ owner)  : CCommodityType(CNullCommodityType::typeid)
{
	_phNullCommodityType = &childNative;
	_ppNullCommodityType = &static_cast<boost::shared_ptr<QuantLib::NullCommodityType>>(childNative.currentLink());
    _ppCommodityType = new boost::shared_ptr<QuantLib::CommodityType> (boost::dynamic_pointer_cast<QuantLib::CommodityType> (*_ppNullCommodityType));
    _NullCommodityTypeOwner = owner;
}
Cephei::QL::Experimental::Commodities::CNullCommodityType::CNullCommodityType (QuantLib::Handle<QuantLib::NullCommodityType> childNative)  : CCommodityType(CNullCommodityType::typeid)
{
	_phNullCommodityType = &childNative;
	_ppNullCommodityType = &static_cast<boost::shared_ptr<QuantLib::NullCommodityType>>(childNative.currentLink());
    _ppCommodityType = new boost::shared_ptr<QuantLib::CommodityType> (boost::dynamic_pointer_cast<QuantLib::CommodityType> (*_ppNullCommodityType));
}
#endif
#ifdef STRUCT
Cephei::QL::Experimental::Commodities::CNullCommodityType::CNullCommodityType (QuantLib::NullCommodityType childNative)  : CCommodityType(CNullCommodityType::typeid)
{
#ifdef HANDLE
	_phNullCommodityType = NULL;
#endif
	_ppNullCommodityType = new boost::shared_ptr<QuantLib::NullCommodityType> (new QuantLib::NullCommodityType (childNative));
    _ppCommodityType = new boost::shared_ptr<QuantLib::CommodityType> (boost::dynamic_pointer_cast<QuantLib::CommodityType> (*_ppNullCommodityType));
}
#endif

Cephei::QL::Experimental::Commodities::CNullCommodityType::~CNullCommodityType ()
{
    if (_ppNullCommodityType != NULL)
    {
	    delete _ppNullCommodityType;
        _ppNullCommodityType = NULL;
    }
}
Cephei::QL::Experimental::Commodities::CNullCommodityType::!CNullCommodityType ()
{
    if (_ppNullCommodityType != NULL)
    {
	    delete _ppNullCommodityType;
    }
}
QuantLib::NullCommodityType& Cephei::QL::Experimental::Commodities::CNullCommodityType::GetReference ()
{
    if (_ppNullCommodityType == NULL) throw gcnew NativeNullException ();
	return **_ppNullCommodityType;
}
boost::shared_ptr<QuantLib::NullCommodityType>& Cephei::QL::Experimental::Commodities::CNullCommodityType::GetShared ()
{
    if (_ppNullCommodityType == NULL) throw gcnew NativeNullException ();
	return *_ppNullCommodityType;
}
QuantLib::NullCommodityType* Cephei::QL::Experimental::Commodities::CNullCommodityType::GetPointer ()
{
    if (_ppNullCommodityType == NULL) throw gcnew NativeNullException ();
	return &**_ppNullCommodityType;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::NullCommodityType>& Cephei::QL::Experimental::Commodities::CNullCommodityType::GetHandle ()
{
	if (_phNullCommodityType == NULL)
	{
		_phNullCommodityType = new Handle<QuantLib::NullCommodityType> (*_ppNullCommodityType);
	}
	return *_phNullCommodityType;
}
#endif
bool Cephei::QL::Experimental::Commodities::CNullCommodityType::HasNative () 
{
	return (_ppNullCommodityType != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Experimental::Commodities::INullCommodityType^ Cephei::QL::Experimental::Commodities::CNullCommodityType_Factory::Create ()
{
    return gcnew CNullCommodityType ();
}
